package com.eascs.admin.o2o.backfee.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.eascs.admin.o2o.backfee.service.O2OComBankFeeService;
import com.eascs.admin.o2o.internal.entity.LoanapplyExpand;
import com.eascs.admin.o2o.internal.service.LoanapplyExpandService;
import com.eascs.admin.o2o.internal.util.BaseUtils;
import com.eascs.admin.o2o.internal.util.StatusContexts;
import com.eascs.admin.o2o.loan.entity.O2oLoanUserEntity;
import com.eascs.admin.o2o.loan.entity.O2oLoanapplyEntity;
import com.eascs.admin.o2o.loan.service.O2oLoanUserService;
import com.eascs.admin.o2o.loan.service.O2oLoanapplyService;
import com.eascs.app.log.Logger;
import com.eascs.app.log.LoggerFactory;
import com.eascs.site.controller.BaseRestController;
import com.eascs.site.view.BaseRestResult;
import com.eascs.site.view.HtmlRestResult;
import com.eascs.site.view.ViewContext;
import com.eascs.workflow.common.entity.wf.ProcessTemplate;

@RestController
@RequestMapping("/rbond")
public class O2oBondFeeRestController extends BaseRestController {

	@Autowired
	O2OComBankFeeService o2oComBankFeeService;
	@Autowired
	private O2oLoanapplyService o2oLoanapplyService;

	@Autowired
	private LoanapplyExpandService loanapplyExpandService;
	@Autowired
	private BaseUtils baseUtils;
	@Autowired
	private O2oLoanUserService o2oLoanUserService;
	@Value("${o2o.admin.agreeUrlShow}")
	private String agreeUrlShow;

	private static Logger log = LoggerFactory.getLogger(O2oBondFeeRestController.class);


	

	/**
	 * @Title: detail
	 * @Description: 收费详情页
	 * @author 张庆奇
	 * @param billCode
	 * @return
	 * @return BaseRestResult<String>
	 * @throws
	 * @date 2017年7月24日 上午10:07:32
	 */
	@RequestMapping("/detail")
	public BaseRestResult<String> detail(String billCode){
		O2oLoanapplyEntity loan = o2oLoanapplyService.fingByBillCode(billCode);
		LoanapplyExpand loanapplyExpand = loanapplyExpandService.queryLoanapplyNo(loan.getLoanapplyNo());
		O2oLoanUserEntity loanUser = o2oLoanUserService.findById(loan.getLoanId(), loan.getLoanapplyNo());
		ViewContext.put("loanapply", loan);
		ViewContext.put("loanapplyExpand", loanapplyExpand);
		ViewContext.put("loanUser", loanUser);
		String processType="";
		
		if(loan.getLoanType().equals(StatusContexts.LOAN_TYPE_BK)||StatusContexts.LOAN_TYPE_BP.equals(loan.getLoanType())||StatusContexts.LOAN_TYPE_BP_JX.equals(loan.getLoanType())||StatusContexts.LOAN_TYPE_SG.equals(loan.getLoanType())||StatusContexts.LOAN_TYPE_YC.equals(loan.getLoanType())||StatusContexts.LOAN_TYPE_SC.equals(loan.getLoanType())){
			processType=ProcessTemplate.PROECESS_TYPE_DEPOSIT;
		}else{
			if(loan.getLoanType().equals(StatusContexts.LOAN_TYPE_FQ)||loan.getLoanType().equals(StatusContexts.LOAN_TYPE_EA)){
				processType=String.valueOf(ProcessTemplate.PROECESS_TYPE_DEPOSIT_FQ);
			}
		}
		log.info("流程模板类型：{}", processType);
		
		String agreeUrl = agreeUrlShow+loan.getLoanapplyNo()+"&processType="+processType;
		ViewContext.put("agreeUrl", agreeUrl);

		return HtmlRestResult.popHtmlFragment("bond/bond_detail");
	}

	
	
}
